@extends("admin.layout.main")

@section("content")

    <style>
        table thead tr th {
            text-align: center
        }

        table tbody tr td {
            text-align: center
        }
    </style>
    <div class="page-header">
        <h1>
            待结算积分
        </h1>
    </div>
    <div class="page-header">
        <form action="">
            <a onclick="downLoad()" class="btn btn-xs btn-success" style="margin-right: 20px;">导出</a>
            <input type="checkbox" id="all_check" onclick="all_select(this)">
            全选
            <label style="margin-left: 20px;">
                创客ID：
                <input type="text" name="keyword" value="{{ $where['keyword'] }}">
            </label>
            <label>
                发放状态：
                <select name="status" id="">
                    <option value="0">全部</option>
                    <option value="3" @if($where['status']==3) selected @endif>待发放</option>
                    {{--<option value="1" @if($where['status']==1) selected @endif>已发放</option>--}}
                    <option value="2" @if($where['status']==2) selected @endif>不发放</option>
                </select>
            </label>
            <label>
                日期：
                <input type="text" id="start_time" name="start_time" value="{{ $where['start_time'] }}">
                至
                <input type="text" id="end_time" name="end_time" value="{{ $where['end_time'] }}">
            </label>
            <button class="btn btn-xs btn-primary">搜索</button>
        </form>
    </div>


    <!-- div.table-responsive -->

    <!-- div.dataTables_borderWrap -->
    <div>
        <table id="simple-table" class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th>发放日期</th>
                <th>创客ID</th>
                <th>创客昵称</th>
                <th>手机号码</th>
                <th>变动类型</th>
                <th>发放数额</th>
                <th>发放状态</th>
                <th>操作</th>
            </tr>
            </thead>

            <tbody id="data">
            @foreach($data as $v)
            <tr>
                <td>@if($v->status == 3)<input type="checkbox" name="ids[]" value="{{ $v->id }}" style="margin-right: 5px" onclick="check_all_select(this)">@endif {{ $v->created_at }}</td>
                <td>{{ $v->user['id'] }}</td>
                <td>{{ $v->user['name'] }}</td>
                <td>{{ $v->user['mobile'] }}</td>
                <td>积分</td>
                <td>{{ $v->cash }}</td>
                <td>{{ $statusArr[$v->status] }}</td>
                <td>
                    @if($v->status == 3)<a class="btn btn-xs btn-danger" onclick="one_check({{ $v->id }})">审核不发放</a>@endif
                </td>
            </tr>
            @endforeach
            </tbody>
        </table>
        <div class="pagination pagination-centered">
            <button class="btn btn-xs btn-danger" onclick="batch_check()">审核不发放</button>
            {{ $data->appends($where)->links('admin.layout.page') }}
        </div>
    </div>
    <div class="bootbox modal fade bootbox-prompt in" id="check-remark" tabindex="-1" role="dialog" style="display: none;margin-top:15%">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="bootbox-close-button close" onclick="cancel_check()">×</button>
                    <h4 class="modal-title">备注</h4>
                </div>
                <div class="modal-body">
                    <div class="bootbox-body">
                        <form class="bootbox-form">
                            <input type="hidden" name="check-ids" value="">
                            <input class="bootbox-input bootbox-input-text form-control" autocomplete="off" required type="text" id="remark">
                        </form>
                    </div>
                </div>
                <div class="modal-footer">
                    <button data-bb-handler="confirm" type="button" class="btn btn-primary" onclick="confirm_check()">确认</button>
                    <button data-bb-handler="cancel" type="button" class="btn btn-default" onclick="cancel_check()">取消</button>
                </div>
            </div>
        </div>
    </div>
    <link rel="stylesheet" href="/plugins/jedate/jedate.css"/>
    <script src="/plugins/jedate/jedate.min.js"></script>
    <script src="{{ config('global.assets_path') }}js/jquery.validate.min.js"></script>
    <script src="{{ config('global.assets_path') }}js/messages_zh.js"></script>
    <script src="/plugins/layui/layui.js"></script>
    <script src="/plugins/layui/layui_component.js"></script>
    <script src="/js/ajax.js"></script>
    <script>
        function downLoad() {
            var length = $('#data').find('tr').length;
            if(length <= 0){
                showMessage('暂无数据可导！',0);
                return false;
            }
            var keyword = '{{ $where['keyword'] }}';
            var status = '{{ $where['status'] }}';
            var start_time = '{{ $where['start_time'] }}';
            var end_time = '{{ $where['end_time'] }}';
            window.location.href = "{{ url('/admin/finance/downRegisterCoinList') }}?type=1&status=" + status + "&keyword=" + keyword + "&start_time=" + start_time + "&end_time=" + end_time;
        }
        function all_select(obj) {
            $('#simple-table').find("input" ).prop('checked',obj.checked);
        }
        function check_all_select(obj) {
            var leng = $('#simple-table').find('input[name="ids[]"]').length;
            var check_leng = $('#simple-table').find('input[name="ids[]"]:checked').length;
            if(leng == check_leng){
                $('#all_check').prop('checked',obj.checked);
            }else{
                $('#all_check').attr('checked',false);
            }
        }
        // 批量处理
        function batch_check() {
            var checkeds = $('#simple-table').find('input:checked');
            if(checkeds.length == 0){
                showMessage('未选择记录', 0);
                return false;
            }
            $('#check-remark').show();
            $('input[name="check-ids"]').val('');
        }

        function one_check(id) {
            $('#check-remark').show();
            $('input[name="check-ids"]').val(id);
        }
        function cancel_check() {
            $('#remark').val('');
            $('#check-remark').hide();
        }
        function confirm_check() {
            var remark = $('#remark').val();
            if(!remark){
                showMessage('未填写不通过原因！',0);
                return false;
            }
            var id = $('input[name="check-ids"]').val();
            if(id){
                var ids = id;
            }else{
                var checkeds = $('#simple-table').find('input:checked');
                var ids = [];
                $.each(checkeds, function (i, item) {
                    ids.push($(this).val());
                })
            }
            $('#remark').val('');
            $('#check-remark').hide();
            var data = {'ids':ids,'status':2,'remark':remark,'type':1};
            var url = '{{ route('admin.finance.ajaxInteCoin') }}';
            ajaxRequest(data,url,'post');
        }
        var start = {
            dateCell: "#start_time",
            format: "YYYY-MM-DD",
            isinitVal: false,
            isTime: false, //isClear:false,
            maxDate: "{{ $where['end_time'] }}",
            minDate: "",
            choosefun: function (datas) {
                end.minDate = datas;
                $("input[name='begin']").val(datas);
            }
        };
        jeDate(start);
        var end = {
            dateCell: "#end_time",
            format: "YYYY-MM-DD",
            isinitVal: false,
            isTime: false, //isClear:false,
            maxDate: "2099-01-01 23:59:59",
            minDate: "{{ $where['start_time'] }}",
            choosefun: function (datas) {
                start.maxDate = datas;
                $("input[name='end']").val(datas);
            }
        };
        jeDate(end);
    </script>
@endsection